#include "stdafx.h"
#include "ComRegHelper.h"

HRESULT RegisterKeyEntry(const REGISTRY_ENTRY* pKeyEntry)
{
	HKEY hKey;
	LONG ret = RegCreateKeyExW(pKeyEntry->hKey,pKeyEntry->pszKeyName,0,NULL,REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&hKey,NULL);
	if (ret != ERROR_SUCCESS)
		return HRESULT_FROM_WIN32(ret);
	ret = RegSetValueExW(hKey,pKeyEntry->pszValueName,0,REG_SZ,(PBYTE)pKeyEntry->pszData,(wcslen(pKeyEntry->pszData) + 1) * sizeof(WCHAR));
	RegCloseKey(hKey);
	return HRESULT_FROM_WIN32(ret);
}

HRESULT UnregisterKeyEntry(const REGISTRY_ENTRY* pKeyEntry)
{
	DWORD dwError = RegDeleteTreeW(pKeyEntry->hKey,pKeyEntry->pszKeyName);
	if (dwError == ERROR_FILE_NOT_FOUND)
		return S_OK;
	else
		return HRESULT_FROM_WIN32(dwError);
}